<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title><tiles:insertAttribute name="title" ignore="true" /></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<link href="css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css" />
	<link href="css/font-awesome.css" rel="stylesheet">
	<link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600" rel="stylesheet">
	<link href="css/style.css" rel="stylesheet" type="text/css">
	<link href="css/pages/signin.css" rel="stylesheet" type="text/css">
<!-- javascript 정의 -->
<script type="text/javascript">
	var contextPath = "${pageContext.request.contextPath}";
</script>
</head>
<body onload="initLoginId()">
	<div class="navbar navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<a class="btn btn-navbar" data-toggle="collapse"
					data-target=".nav-collapse"> <span class="icon-bar"></span> <span
					class="icon-bar"></span> <span class="icon-bar"></span>
				</a> <a class="brand" href="index.do"> Sangrok Admin Site </a>
				<!--/.nav-collapse -->
			</div>
			<!-- /container -->
		</div>
		<!-- /navbar-inner -->
	</div>
	<!-- /navbar -->
	<div class="account-container">
		<div class="content clearfix">
			<form onsubmit="return loginAct(); return false;" method="post">
				<h1>Member Login</h1>
				<div class="login-fields">
					<p>Please provide your details</p>
					<div class="field">
						<label for="username">Username</label>
						<input type="text" id="txtLoginId" name="txtLoginId" value="" placeholder="Username" class="login username-field" />
					</div>
					<!-- /field -->
					<div class="field">
						<label for="password">Password:</label>
						<input type="password" id="txtLoginPwd" name="txtLoginPwd" value="" placeholder="Password" class="login password-field" />
					</div>
					<!-- /password -->
				</div>
				<!-- /login-fields -->
				<div class="login-actions">
					<span class="login-checkbox">
						<input id="chkLoginIdSave" name="chkLoginIdSave" type="checkbox" class="field login-checkbox" value="First Choice" tabindex="4" />
						<label class="choice" for="Field">Keep me signed in</label>
					</span>
					<button class="button btn btn-success btn-large">Sign In</button>
				</div>
				<!-- .actions -->
			</form>
		</div>
		<!-- /content -->
	</div>
	<!-- /account-container -->

	<!-- /login-extra -->
	<script src="<c:url value='/js/plugin/jquery-1.7.2.min.js'/>"></script>
	<script src="<c:url value='/js/template/bootstrap.js'/>"></script>
	<script src="<c:url value='/js/template/signin.js'/>"></script>
	<script type="text/javascript">
	function loginAct(){
		$.ajax({
			type: "POST"
			, url: contextPath+"/auth.json"
			, data: {
				id: $("#txtLoginId").val()
				, pwd: $("#txtLoginPwd").val()
			}
		}).done(function( msg ) {
			if(msg["result"]["result"]){
				if($("#chkLoginIdSave").attr("checked")){
					setCookie("sr_login_id", $("#txtLoginId").val(), 365);
				}
				else{
					setCookie("sr_login_id", $("#txtLoginId").val(), -1);
				}
				location.reload();
			}
			else{
				alert("로그인 실패 : " + msg["result"]["errType"]);
			}
		});
		return false;
	}

	function initLoginId(){
		var cookieLoginId = getCookie("sr_login_id");
		if(cookieLoginId != ""){
			$("#chkLoginIdSave").attr("checked", "checked");
			$("#txtLoginId").val(cookieLoginId);
		}
	}

	function setCookie(name, value, expiredays){
		var today = new Date();
		today.setDate( today.getDate() + expiredays );
		document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
	}

	function getCookie(name){
		var cook = document.cookie + ";";
		var idx = cook.indexOf(name, 0);
		var val = "";

		if(idx != -1){
			cook = cook.substring(idx, cook.length);
			var begin = cook.indexOf("=", 0) + 1;
			var end = cook.indexOf(";", begin);
			val = unescape( cook.substring(begin, end) );
		}
		return val;
	}
	</script>
</body>
</html>